Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
How to replace three dots added by -webkit-line-clamp with "read more" text

I am using -webkit-line-clamp to truncate text like the below example

.box {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;  
  overflow: hidden;
  width: 100px;
}
<div class="box">
  <p>Hey, don't cut me off like that. I want to speak my mind and don't appreciate being put into a box.</p>
</div>

Here I am getting 3 dots end of truncation, I want to have a "read more" link at the end of truncated text instead of .... Please let me know if this can be achieved through css or JS

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

How about this code? This code removes button when doesn't overflow.

var container = document.getElementsByClassName('container');
var i;
for (i=0;i<container.length;i++) {
  if (container[i].firstElementChild.scrollHeight<=container[i].firstElementChild.clientHeight) {
    container[i].lastElementChild.style.display = 'none';
  }
}
function more(x) {
  var box = x.parentElement.firstElementChild;
  if (!box.classList.contains('box-more')) {
    box.classList.add('box-more');
    x.innerHTML = "Close";
  }
  else {
    box.classList.remove('box-more');
    x.innerHTML = "Read More";
  }
}
.box {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;  
  overflow: hidden;
  width: 100px;
}
.box-more {
  -webkit-line-clamp: unset !important;
}
<div class="container">
  <div class="box">
    <p>Hey, don't cut me off like that. I want</p>
  </div>
  <button onclick="more(this)">Read More</button>
</div>
<div class="container">
  <div class="box">
    <p>Hey, don't cut me off like that. I want to speak my mind and don't appreciate being put into a box.</p>
  </div>
  <button onclick="more(this)">Read More</button>
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!